<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> - 会员等级配置</title>
    <link href="./js/bootstrap.min.css" rel="stylesheet">
    <link href="./js/bootstrap-icons.css" rel="stylesheet">
    <link rel="stylesheet" href="css/index.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f8fafc;
        }

        /* 顶部导航栏 */
        .top-nav {
            height: 60px;
            background-color: #2563eb;
            color: white;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 20px;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 1000;
        }

        .logo {
            font-size: 20px;
            font-weight: bold;
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        /* 主体布局 */
        .main-container {
            display: flex;
            margin-top: 60px;
            height: calc(100vh - 60px);
        }

        /* 左侧菜单栏 */
        .sidebar {
            width: 220px;
            background-color: #1e293b;
            color: white;
            height: 100%;
            position: fixed;
            overflow-y: auto;
            transition: all 0.3s;
            z-index: 900;
        }

        .sidebar.collapsed {
            width: 80px;
        }

        .menu-toggle {
            padding: 15px 20px;
            cursor: pointer;
            border-bottom: 1px solid #334155;
        }

        .menu-items {
            padding: 10px 0;
        }

        .menu-item {
            padding: 12px 20px;
            display: flex;
            align-items: center;
            gap: 12px;
            cursor: pointer;
            transition: background 0.2s;
            position: relative;
        }

        .menu-item:hover {
            background-color: #334155;
        }

        .menu-item.active {
            background-color: #2563eb;
        }

        .menu-text {
            white-space: nowrap;
            overflow: hidden;
        }

        .sidebar.collapsed .menu-text {
            display: none;
        }

        .sidebar.collapsed .menu-item {
            justify-content: center;
        }

        .submenu {
            padding-left: 40px;
            background-color: #0f172a;
        }

        .submenu-item {
            padding: 8px 20px;
            display: flex;
            align-items: center;
            gap: 12px;
            cursor: pointer;
            transition: background 0.2s;
        }

        .submenu-item:hover {
            background-color: #1e293b;
        }

        .submenu-item.active {
            background-color: #2563eb;
        }

        /* 内容区 */
        .content {
            flex: 1;
            margin-left: 220px;
            padding: 20px;
            transition: margin-left 0.3s;
        }

        .sidebar.collapsed ~ .content {
            margin-left: 80px;
        }

        /* 页面标题与操作 */
        .page-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }

        .page-title {
            font-size: 24px;
            font-weight: 600;
            color: #1e293b;
        }

        /* 按钮样式 */
        .btn {
            padding: 8px 16px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            border: none;
            margin: 0 5px;
        }

        .btn-primary {
            background-color: #2563eb;
            color: white;
        }

        .btn-success {
            background-color: #10b981;
            color: white;
        }

        .btn-warning {
            background-color: #f59e0b;
            color: white;
        }

        .btn-danger {
            background-color: #ef4444;
            color: white;
        }

        .btn-outline {
            background-color: transparent;
            border: 1px solid #cbd5e1;
            color: #64748b;
        }

        .btn-sm {
            padding: 4px 8px;
            font-size: 12px;
        }

        /* 等级卡片列表 */
        .level-cards-container {
            overflow-x: auto;
            padding: 10px 0;
            margin-bottom: 20px;
        }

        .level-cards {
            display: flex;
            gap: 20px;
            min-width: fit-content;
        }

        .level-card {
            width: 300px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            padding: 20px;
            cursor: move;
            transition: transform 0.2s, box-shadow 0.2s;
        }

        .level-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        }

        .level-card.dragging {
            opacity: 0.5;
        }

        .level-header {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 15px;
        }

        .level-icon {
            font-size: 24px;
        }

        .level-name {
            font-size: 18px;
            font-weight: 600;
            color: #1e293b;
        }

        .level-sort {
            color: #64748b;
            font-size: 14px;
            margin-bottom: 15px;
        }

        .level-benefits {
            margin-bottom: 15px;
        }

        .benefit-item {
            color: #64748b;
            font-size: 14px;
            margin-bottom: 5px;
        }

        .level-status {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            padding: 4px 8px;
            border-radius: 12px;
            font-size: 12px;
            font-weight: 500;
            margin-bottom: 15px;
        }

        .status-active {
            background-color: #dcfce7;
            color: #166534;
        }

        .status-inactive {
            background-color: #fef3c7;
            color: #92400e;
        }

        .status-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            display: inline-block;
        }

        .dot-active {
            background-color: #10b981;
        }

        .dot-inactive {
            background-color: #f59e0b;
        }

        .level-actions {
            display: flex;
            gap: 10px;
        }

        /* 提示信息 */
        .hint {
            color: #64748b;
            font-size: 14px;
            margin-bottom: 20px;
            padding: 10px;
            background-color: #f1f5f9;
            border-radius: 4px;
        }

        /* 弹窗样式 */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0,0,0,0.5);
            z-index: 2000;
            align-items: center;
            justify-content: center;
        }

        .modal.show {
            display: flex;
        }

        .modal-content {
            background: white;
            border-radius: 8px;
            width: 600px;
            max-width: 90%;
            max-height: 90%;
            overflow-y: auto;
        }

        .modal-header {
            padding: 20px;
            border-bottom: 1px solid #e2e8f0;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .modal-body {
            padding: 20px;
        }

        .modal-footer {
            padding: 20px;
            border-top: 1px solid #e2e8f0;
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }

        .close {
            font-size: 24px;
            cursor: pointer;
        }

        /* 表单样式 */
        .form-group {
            margin-bottom: 15px;
        }

        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: 500;
        }

        .form-group input,
        .form-group select,
        .form-group textarea {
            width: 100%;
            padding: 8px 12px;
            border: 1px solid #cbd5e1;
            border-radius: 4px;
        }

        .form-row {
            display: flex;
            gap: 15px;
            margin-bottom: 15px;
        }

        .form-col {
            flex: 1;
        }

        /* 上传区域 */
        .upload-area {
            border: 2px dashed #cbd5e1;
            border-radius: 4px;
            padding: 20px;
            text-align: center;
            cursor: pointer;
            transition: border-color 0.3s;
        }

        .upload-area:hover {
            border-color: #2563eb;
        }

        /* 表格样式 */
        .table-container {
            overflow-x: auto;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #e2e8f0;
        }

        th {
            background-color: #f1f5f9;
            font-weight: 600;
            color: #1e293b;
        }

        tr:hover {
            background-color: #f8fafc;
        }

        /* 步骤指示器 */
        .steps {
            display: flex;
            justify-content: center;
            margin-bottom: 20px;
        }

        .step {
            display: flex;
            align-items: center;
            margin: 0 10px;
        }

        .step-number {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background-color: #cbd5e1;
            color: #64748b;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
        }

        .step-number.active {
            background-color: #2563eb;
            color: white;
        }

        .step-label {
            color: #64748b;
        }

        .step-label.active {
            color: #1e293b;
            font-weight: 500;
        }

        /* 响应式 */
        @media (max-width: 768px) {
            .page-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 15px;
            }
            
            .form-row {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
    <!-- 顶部导航栏 -->
    <div class="top-nav">
        <div class="logo">管理系统</div>
        <div class="user-info">
            <div class="notification-icon">🔔 通知中心</div>
            <div class="user-dropdown">
                <span>张经理 ▼</span>
            </div>
        </div>
    </div>

    <!-- 主体布局 -->
    <div class="main-container">
        <!-- 左侧菜单栏 -->
        <div class="sidebar" id="sidebar">
            <div class="menu-toggle" onclick="toggleSidebar()">☰ 菜单</div>
            <div class="menu-items">
                <div class="menu-item">
                    <a href="./index.html">
                        <span>📊</span>
                        <span class="menu-text">仪表盘</span>
                    </a>
                  
                </div>
                <div class="menu-item">
                    <a href="./dianpu.html">
                        <span>🏪</span>
                        <span class="menu-text">店铺管理</span>
                    </a>
                   
                </div>
                <div class="menu-item">
                    <a href="./jiqiren.html">
                        <span>🤖</span>
                        <span class="menu-text">机器人管理</span>
                    </a>
                 
                </div>
                <div class="menu-item">
                    <a href="./order.html">
                        <span>📋</span>
                        <span class="menu-text">订单管理</span>
                    </a>
                   
                </div>
                <div class="menu-item active">
                    <span>👥</span>
                    <span class="menu-text">用户会员管理</span>
                    <span>▶</span>
                </div>
                <div class="submenu">
                    <div class="submenu-item">
                        <a href="./user.html">
                            <span>├─</span>
                            <span class="menu-text">用户会员列表</span>
                        </a>
                      
                    </div>
                    <div class="submenu-item active">
                        <a href="./vip.html">
                            <span>├─</span>
                            <span class="menu-text">会员等级配置</span>
                        </a>
                        
                    </div>
                </div>
                <div class="menu-item ">
                    <a href="./fuwu.html">
                        <span>🎯</span>
                        <span class="menu-text">服务套餐类型</span>
                    </a>
                </div>
                <div class="menu-item">
                    <span>🎯</span>
                    <span class="menu-text">促销管理(二期)</span>
                </div>
                <div class="menu-item">
                    <span>📈</span>
                    <span class="menu-text">数据统计(二期)</span>
                </div>
                <div class="menu-item">
                    <span>⚙️</span>
                    <span class="menu-text">系统设置</span>
                </div>
            </div>
        </div>

        <!-- 中间内容区 -->
        <div class="content">
            <!-- 页面标题与操作 -->
            <div class="page-header">
                <h1 class="page-title">会员等级配置</h1>
                <div>
                    <button class="btn btn-primary" onclick="showAddLevelModal()">
                        <i class="bi bi-plus-lg"></i> 新增等级
                    </button>
                    <button class="btn btn-outline" onclick="showBenefitLibraryModal()">
                        <i class="bi bi-gear"></i> 权益库管理
                    </button>
                </div>
            </div>

            <!-- 等级卡片列表 -->
            <div class="hint">
                提示：拖动卡片可调整等级排序，排序决定小程序端展示顺序
            </div>

            <div class="level-cards-container">
                <div class="level-cards" id="levelCards">
                    <!-- VIP1 等级卡片 -->
                    <div class="level-card" draggable="true" data-id="1">
                        <div class="level-header">
                            <span class="level-icon">🥉</span>
                            <span class="level-name">VIP1（青铜会员）</span>
                        </div>
                        <div class="level-sort">等级排序：1</div>
                        <div class="level-benefits">
                            <div class="benefit-item">• 服务9.5折</div>
                            <div class="benefit-item">• 每月1次免费洗头</div>
                            <div class="benefit-item">• 普通预约权</div>
                        </div>
                        <div class="level-status status-active">
                            <span class="status-dot dot-active"></span>
                            启用
                        </div>
                        <div class="level-actions">
                            <button class="btn btn-outline btn-sm" onclick="editLevel(1)">
                                <i class="bi bi-pencil"></i> 编辑
                            </button>
                            <button class="btn btn-danger btn-sm" onclick="deleteLevel(1)">
                                <i class="bi bi-trash"></i> 删除
                            </button>
                        </div>
                    </div>

                    <!-- VIP2 等级卡片 -->
                    <div class="level-card" draggable="true" data-id="2">
                        <div class="level-header">
                            <span class="level-icon">🥈</span>
                            <span class="level-name">VIP2（黄金会员）</span>
                        </div>
                        <div class="level-sort">等级排序：2</div>
                        <div class="level-benefits">
                            <div class="benefit-item">• 服务9折</div>
                            <div class="benefit-item">• 每月2次免费洗头</div>
                            <div class="benefit-item">• 优先预约权</div>
                        </div>
                        <div class="level-status status-active">
                            <span class="status-dot dot-active"></span>
                            启用
                        </div>
                        <div class="level-actions">
                            <button class="btn btn-outline btn-sm" onclick="editLevel(2)">
                                <i class="bi bi-pencil"></i> 编辑
                            </button>
                            <button class="btn btn-danger btn-sm" onclick="deleteLevel(2)">
                                <i class="bi bi-trash"></i> 删除
                            </button>
                        </div>
                    </div>

                    <!-- VIP3 等级卡片 -->
                    <div class="level-card" draggable="true" data-id="3">
                        <div class="level-header">
                            <span class="level-icon">🥇</span>
                            <span class="level-name">VIP3（钻石会员）</span>
                        </div>
                        <div class="level-sort">等级排序：3</div>
                        <div class="level-benefits">
                            <div class="benefit-item">• 服务8折</div>
                            <div class="benefit-item">• 每月4次免费洗头</div>
                            <div class="benefit-item">• 专属客服</div>
                        </div>
                        <div class="level-status status-inactive">
                            <span class="status-dot dot-inactive"></span>
                            待启用
                        </div>
                        <div class="level-actions">
                            <button class="btn btn-outline btn-sm" onclick="editLevel(3)">
                                <i class="bi bi-pencil"></i> 编辑
                            </button>
                            <button class="btn btn-danger btn-sm" onclick="deleteLevel(3)">
                                <i class="bi bi-trash"></i> 删除
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 新增/编辑等级弹窗 - 步骤1 -->
    <div class="modal" id="addLevelModal">
        <div class="modal-content">
            <div class="modal-header">
                <h5 id="addLevelTitle">新增会员等级</h5>
                <span class="close" onclick="closeAddLevelModal()">&times;</span>
            </div>
            <div class="modal-body">
                <!-- 步骤指示器 -->
                <div class="steps">
                    <div class="step">
                        <div class="step-number active">1</div>
                        <div class="step-label active">基础设置</div>
                    </div>
                    <div class="step">
                        <div class="step-number">2</div>
                        <div class="step-label">权益配置</div>
                    </div>
                </div>

                <!-- 步骤1：基础设置 -->
                <div id="step1">
                    <div class="form-group">
                        <label>等级名称 *</label>
                        <input type="text" id="levelName" placeholder="如：白银会员">
                    </div>
                    <div class="form-group">
                        <label>等级图标 *</label>
                        <div class="upload-area" onclick="triggerFileUpload()">
                            <i class="bi bi-cloud-upload" style="font-size: 24px;"></i>
                            <p>点击上传或拖拽图片到此处</p>
                            <p style="font-size: 12px; color: #64748b;">建议尺寸60*60px</p>
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-col">
                            <div class="form-group">
                                <label>等级排序</label>
                                <input type="number" id="levelSort" placeholder="数字越小越靠前">
                            </div>
                        </div>
                        <div class="form-col">
                            <div class="form-group">
                                <label>状态</label>
                                <div>
                                    <label style="margin-right: 20px;">
                                        <input type="radio" name="levelStatus" value="启用" checked> 启用
                                    </label>
                                    <label>
                                        <input type="radio" name="levelStatus" value="停用"> 停用
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 步骤2：权益配置 -->
                <div id="step2" style="display: none;">
                    <div class="form-group">
                        <label>选择权益（可多选）</label>
                        <div style="border: 1px solid #e2e8f0; border-radius: 4px; padding: 15px; margin-top: 10px;">
                            <label style="display: block; margin: 10px 0;">
                                <input type="checkbox"> 服务9折
                            </label>
                            <label style="display: block; margin: 10px 0;">
                                <input type="checkbox"> 免费洗头3次
                            </label>
                            <label style="display: block; margin: 10px 0;">
                                <input type="checkbox"> 头皮护理5次
                            </label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-outline" onclick="closeAddLevelModal()">取消</button>
                <button class="btn btn-primary" id="nextBtn" onclick="nextStep()">下一步</button>
                <button class="btn btn-primary" id="saveBtn" onclick="saveLevel()" style="display: none;">保存</button>
            </div>
        </div>
    </div>

    <!-- 权益库管理弹窗 -->
    <div class="modal" id="benefitLibraryModal">
        <div class="modal-content" style="width: 800px;">
            <div class="modal-header">
                <h5>会员权益库</h5>
                <span class="close" onclick="closeBenefitLibraryModal()">&times;</span>
            </div>
            <div class="modal-body">
                <div style="margin-bottom: 20px;">
                    <button class="btn btn-primary" onclick="showAddBenefitModal()">
                        <i class="bi bi-plus-lg"></i> 新增权益
                    </button>
                </div>
                <div class="table-container">
                    <table>
                        <thead>
                            <tr>
                                <th>权益名称</th>
                                <th>权益类型</th>
                                <th>权益描述</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>服务9折</td>
                                <td>折扣类</td>
                                <td>所有机器人服务享9折优惠</td>
                                <td><span class="badge bg-success">启用</span></td>
                                <td>
                                    <button class="btn btn-outline btn-sm">编辑</button>
                                    <button class="btn btn-danger btn-sm">删除</button>
                                </td>
                            </tr>
                            <tr>
                                <td>免费洗头</td>
                                <td>服务类</td>
                                <td>免费使用基础洗头服务</td>
                                <td><span class="badge bg-success">启用</span></td>
                                <td>
                                    <button class="btn btn-outline btn-sm">编辑</button>
                                    <button class="btn btn-danger btn-sm">删除</button>
                                </td>
                            </tr>
                            <tr>
                                <td>优先预约权</td>
                                <td>功能类</td>
                                <td>支持提前48小时预约</td>
                                <td><span class="badge bg-success">启用</span></td>
                                <td>
                                    <button class="btn btn-outline btn-sm">编辑</button>
                                    <button class="btn btn-danger btn-sm">删除</button>
                                </td>
                            </tr>
                            <tr>
                                <td>专属客服</td>
                                <td>服务类</td>
                                <td>享受专属客服服务</td>
                                <td><span class="badge bg-success">启用</span></td>
                                <td>
                                    <button class="btn btn-outline btn-sm">编辑</button>
                                    <button class="btn btn-danger btn-sm">删除</button>
                                </td>
                            </tr>
                            <tr>
                                <td>生日特权</td>
                                <td>服务类</td>
                                <td>生日当月享受额外服务</td>
                                <td><span class="badge bg-success">启用</span></td>
                                <td>
                                    <button class="btn btn-outline btn-sm">编辑</button>
                                    <button class="btn btn-danger btn-sm">删除</button>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-outline" onclick="closeBenefitLibraryModal()">关闭</button>
            </div>
        </div>
    </div>

    <!-- 新增权益弹窗 -->
    <div class="modal" id="addBenefitModal">
        <div class="modal-content">
            <div class="modal-header">
                <h5>新增权益</h5>
                <span class="close" onclick="closeAddBenefitModal()">&times;</span>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label>权益名称 *</label>
                    <input type="text" placeholder="请输入权益名称">
                </div>
                <div class="form-group">
                    <label>权益类型 *</label>
                    <select>
                        <option value="">请选择权益类型</option>
                        <option value="折扣类">折扣类</option>
                        <option value="服务类">服务类</option>
                        <option value="功能类">功能类</option>
                        <option value="优惠券类">优惠券类</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>权益描述 *</label>
                    <textarea rows="3" placeholder="请输入权益描述"></textarea>
                </div>
                <div class="form-group">
                    <label>状态</label>
                    <div>
                        <label style="margin-right: 20px;">
                            <input type="radio" name="benefitStatus" value="启用" checked> 启用
                        </label>
                        <label>
                            <input type="radio" name="benefitStatus" value="停用"> 停用
                        </label>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-outline" onclick="closeAddBenefitModal()">取消</button>
                <button class="btn btn-primary" onclick="saveBenefit()">保存</button>
            </div>
        </div>
    </div>

    <script>
        // 切换侧边栏
        function toggleSidebar() {
            const sidebar = document.getElementById('sidebar');
            sidebar.classList.toggle('collapsed');
        }

        // 显示新增等级弹窗
        function showAddLevelModal() {
            document.getElementById('addLevelTitle').textContent = '新增会员等级';
            document.getElementById('step1').style.display = 'block';
            document.getElementById('step2').style.display = 'none';
            document.getElementById('nextBtn').style.display = 'inline-block';
            document.getElementById('saveBtn').style.display = 'none';
            document.getElementById('addLevelModal').classList.add('show');
        }

        // 关闭新增等级弹窗
        function closeAddLevelModal() {
            document.getElementById('addLevelModal').classList.remove('show');
        }

        // 下一步
        function nextStep() {
            document.getElementById('step1').style.display = 'none';
            document.getElementById('step2').style.display = 'block';
            document.getElementById('nextBtn').style.display = 'none';
            document.getElementById('saveBtn').style.display = 'inline-block';
        }

        // 保存等级
        function saveLevel() {
            alert('会员等级已保存');
            closeAddLevelModal();
        }

        // 编辑等级
        function editLevel(id) {
            document.getElementById('addLevelTitle').textContent = '编辑会员等级';
            document.getElementById('step1').style.display = 'block';
            document.getElementById('step2').style.display = 'none';
            document.getElementById('nextBtn').style.display = 'inline-block';
            document.getElementById('saveBtn').style.display = 'none';
            document.getElementById('addLevelModal').classList.add('show');
        }

        // 删除等级
        function deleteLevel(id) {
            if (confirm('确定要删除该会员等级吗？')) {
                alert('会员等级已删除');
            }
        }

        // 显示权益库管理弹窗
        function showBenefitLibraryModal() {
            document.getElementById('benefitLibraryModal').classList.add('show');
        }

        // 关闭权益库管理弹窗
        function closeBenefitLibraryModal() {
            document.getElementById('benefitLibraryModal').classList.remove('show');
        }

        // 显示新增权益弹窗
        function showAddBenefitModal() {
            document.getElementById('addBenefitModal').classList.add('show');
        }

        // 关闭新增权益弹窗
        function closeAddBenefitModal() {
            document.getElementById('addBenefitModal').classList.remove('show');
        }

        // 保存权益
        function saveBenefit() {
            alert('权益已保存');
            closeAddBenefitModal();
        }

        // 触发文件上传
        function triggerFileUpload() {
            alert('触发文件上传');
        }

        // 等级卡片拖拽功能
        document.addEventListener('DOMContentLoaded', function() {
            const levelCards = document.getElementById('levelCards');
            let draggedItem = null;

            // 为每个等级卡片添加拖拽事件
            document.querySelectorAll('.level-card').forEach(card => {
                card.addEventListener('dragstart', function() {
                    draggedItem = this;
                    setTimeout(() => this.classList.add('dragging'), 0);
                });

                card.addEventListener('dragend', function() {
                    this.classList.remove('dragging');
                    draggedItem = null;
                });
            });

            // 为容器添加拖拽事件
            levelCards.addEventListener('dragover', function(e) {
                e.preventDefault();
                const afterElement = getDragAfterElement(levelCards, e.clientY);
                const draggable = document.querySelector('.level-card.dragging');
                if (afterElement == null) {
                    levelCards.appendChild(draggable);
                } else {
                    levelCards.insertBefore(draggable, afterElement);
                }
            });

            function getDragAfterElement(container, y) {
                const draggableElements = [...container.querySelectorAll('.level-card:not(.dragging)')];

                return draggableElements.reduce((closest, child) => {
                    const box = child.getBoundingClientRect();
                    const offset = y - box.top - box.height / 2;
                    if (offset < 0 && offset > closest.offset) {
                        return { offset: offset, element: child };
                    } else {
                        return closest;
                    }
                }, { offset: Number.NEGATIVE_INFINITY }).element;
            }
        });

        // 菜单点击事件
        document.querySelectorAll('.menu-item, .submenu-item').forEach(item => {
            item.addEventListener('click', function() {
                document.querySelectorAll('.menu-item, .submenu-item').forEach(i => i.classList.remove('active'));
                this.classList.add('active');
            });
        });
    </script>
</body>
</html>